package com.example.zhunongzonghe.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhunongzonghe.beans.ZnFarmhouseReserveBean;
import com.example.zhunongzonghe.dao.ZnFarmhouseReserveMapper;
import com.example.zhunongzonghe.entity.ZnFarmhouse;
import com.example.zhunongzonghe.entity.ZnFarmhouseReserve;
import com.example.zhunongzonghe.service.IZnFarmhouseReserveService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class ZnFarmhouseReserveServiceImpl extends ServiceImpl<ZnFarmhouseReserveMapper, ZnFarmhouseReserve>
        implements IZnFarmhouseReserveService {

    @Resource
    private ZnFarmhouseReserveMapper reserveMapper;
    @Override
    public Page<ZnFarmhouseReserveBean> getReserveAll(Integer createPage, Integer pageSize, String selectInfo) {
        Page<ZnFarmhouseReserveBean> page = new Page<>(createPage,pageSize);
        MPJLambdaWrapper<ZnFarmhouseReserve> wrapper = new MPJLambdaWrapper<ZnFarmhouseReserve>()
                .selectAll(ZnFarmhouseReserve.class)
                .select(ZnFarmhouse::getHouseName)
                .and(qw -> qw.like(ZnFarmhouse::getHouseName, selectInfo)
                        .or().like(ZnFarmhouseReserve::getReserveName, selectInfo)
                        .or().like(ZnFarmhouseReserve::getReserveNumber, selectInfo)
                        .or().like(ZnFarmhouseReserve::getPhone, selectInfo)
                        .or().like(ZnFarmhouseReserve::getPeopleNum, selectInfo))
                .leftJoin(ZnFarmhouse.class,ZnFarmhouse::getHouseId,ZnFarmhouseReserve::getHouseId);
        Page<ZnFarmhouseReserveBean> znFarmBeanPage = reserveMapper.selectJoinPage(page,ZnFarmhouseReserveBean.class,wrapper);
        return znFarmBeanPage;
    }
}
